<?php include_once "config/config.php"; session_start(); if (isset($_REQUEST['_SESSION'])) die("Get lost Muppet!");
if (!isset($_SESSION['stalas'])) {header('location:index.php');}
if (!isset($_SESSION['pajegos'])) {header('location:userpage.php');}
?>


<div>
    <span class="h2">Pasirinktas vartotojas:</span>
    <?php
        $id = $_SESSION['pajegos'];
        // Nuskaitom, kuri vartotoja pasirinkoma
        $user_db = mysql_query("SELECT vartotojai.id AS 'userID', vartotojai.PasswordQuestion AS klausimas, vartotojai.email AS email,
                                vartotojai.Vardas AS vardas, vartotojai.Pavarde AS pavarde, vartotojai.Telefonas AS telnr,
                                vartotojai.Adresas AS adr, vartotojai.Enabled As enabled FROM vartotojai WHERE vartotojai.id='$id'");
        $role_db = mysql_query("SELECT roleId FROM vartotojuroles WHERE vartotojuroles.VartotojaiId = '$id'");
        $paslaugos_db = mysql_query("SELECT sutartys.id AS sutartisID, sutartys.GaliojaIki AS galiojaIKI,
                                    sutartys.Planas AS paslaugosID, paslaugos.pavadinimas AS paslaugosPavad
                                    FROM vartotojai INNER JOIN sutartys ON sutartys.VartotojaiId = vartotojai.id
                                    INNER JOIN paslaugos ON sutartys.Planas = paslaugos.id WHERE vartotojai.id = '$id'");
        
        $i = 0; $roles = array();
        while($row = mysql_fetch_array($role_db)){
            $roles[$i] = $row['roleId'];
            $i ++;
        }
        $user = array(); $i = 0;
        while($row = mysql_fetch_array($user_db)){
            $user['id'] = $row['userID'];
            $user['klausimas'] = $row['klausimas'];
            $user['email'] = $row['email'];
            $user['vardas'] = $row['vardas'];
            $user['pavarde'] = $row['pavarde'];
            $user['telnr'] = $row['telnr'];
            $user['adr'] = $row['adr'];
            $user['enabled'] = $row['enabled'];
            $i ++;
        }
        echo('<span style="padding-left: 25px;">'.$user['vardas'].' '.$user['pavarde'].'</span>');
        
        echo('<table border = "0">');
        echo('<tr><td><span style="padding-left: 25px; font-weight:bold;">Vartotojo rolė(s): '.'</span></td><td>');
        for($i = 0; $i < count($roles); $i++) {
             echo('<span style="padding-left: 25px; font-weight:bold;">'.$roles[$i].'</span><br />');
        }
        echo('</td></tr></table>');
    ?>
    
    
    <form name="keiciameiciam" action="EditCustomerData-check.php" method="post">
        <div>
            <table border="0" class="lentele" style="vertical-align:top;">
                <colgroup>
                    <col width="200px" />
                    <col width="200px" />
                </colgroup>
                <tr>
                    <td><label>Patvirtinti vartotoją:</label></td>
                    <td><input type="checkbox" class ="input_size" name="editc_enabled" id="editc_enabled"
                    <?php
                        if($user['enabled'] == 1) echo(' checked="checked" />');
                        else echo(' />');
                    ?>
                    </td>
                </tr>
                <tr>
                    <td><label>Keisti vardą:</label></td>
                    <td><input type="text" class ="input_size" name="editc_vardas" id="editc_vardas" value="<?php echo $user['vardas']; ?>" /></td>
                    <td><span class="klaida2" id="err1">!</span></td>
                </tr>
                <tr>
                    <td><label>Keisti pavardę:</label></td>
                    <td><input type="text" class ="input_size" name="editc_pavarde" id="editc_pavarde" value="<?php echo $user['pavarde']; ?>" /></td> 
                    <td><span class="klaida2" id="err2">!</span></td>
                </tr>
                <tr>
                    <td><label>Keisti username:</label></td>
                    <td><input type="text" class ="input_size" name="editc_login" id="editc_login" /></td> 
                    <td><span class="klaida2" id="err3">!</span></td>
                </tr>
                <tr>
                    <td><label>Keisti slaptažodį:</label></td>
                    <td><input type="password" class ="input_size" name="editc_kodas1" id="editc_kodas1" /></td> 
                    <td>
                        <span class="klaida2" id="err4">!</span>
                        <img src="img/help.png" class="hint" alt="password" title="• Slaptažodis privalo būti bent 6 simbolių ir ne ilgesnis, nei 20.&#10;&#13 &#10;&#13• Slaptažodį privalo sudaryti bent viena raidė ir vienas skaičius. &#10;&#13 &#10;&#13• Galite naudoti šiuos simbolius: !@#$%" />
                    </td>
                </tr>
                    <td><label>Pakartokite slaptažodį:</label></td>
                    <td><input type="password" class ="input_size" name="editc_kodas2" id="editc_kodas2" /></td> 
                    <td><span class="klaida2" id="err5">!</span></td>
                </tr>
                <tr>
                    <td><label>Keisti slaptą klausimą:</label></td>
                    <td><input type="text" class ="input_size" name="editc_klausimas" id="editc_klausimas" value="<?php echo $user['klausimas']; ?>" /></td> 
                    <td>
                        <span class="klaida2" id="err6">!</span>
                    </td>
                </tr>
                <tr>
                    <td><label>Keisti slaptą atsakymą:</label></td>
                    <td><input type="text" class ="input_size" name="editc_atsakymas" id="editc_atsakymas" /></td> 
                    <td><span class="klaida2" id="err7">!</span></td>
                </tr>
                <tr>
                    <td><label>Keisti el. pašto adresą:</label></td>
                    <td><input type="text" class ="input_size" name="editc_email" id="editc_email" value="<?php echo $user['email']; ?>" /></td> 
                    <td><span class="klaida2" id="err8">!</span></td>
                </tr>
                <tr>
                    <td><label>Keisti telefono nr.: </label></td>
                    <td><input type="text" class ="input_size" name="editc_tel" id="editc_tel" value="<?php echo $user['telnr']; ?>" /></td> 
                    <td>
                        <span class="klaida2" id="err9">!</span>
                        <img src="img/help.png" class="hint" alt="question" title="Telefono nr. rašykite be tarpų.&#10;&#13Pvz.: +37060122333 " />                    
                    </td>
                </tr>
                <tr>
                    <td><label>Keisti adresą: </label></td>
                    <td><input type="text" class ="input_size" id="editc_adresas" value="<?php echo $user['adr']; ?>" /></td> 
                    <td><span class="klaida2" id="err10">!</span></td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align: right;">
                        <button id="button" value="edit" name="btn" onclick="return tikrinamivesti(this);">Keisti duomenis</button>
                        <!-- <input type="submit" value="Submit" onclick="return validateform(this);" /> -->
                    </td>
                </tr><tr>
                    <td colspan="2" style="text-align: right;">
                        
                              <button id="delete" value="delete" name="btn" onclick="return istrinti(this);">Ištrinti vartotoją</button>
                              
                    </td>
                </tr>
    
                <tr>
                        <td colspan="2">
                            <br />
                            <span class="klaida" id="klaida6">Keisti nepavyko. Pataisykite klaidas ir bandykite dar kartą.</span>
                            <span class="klaida" id="klaida7">Toks vartotojas jau užregistruotas.</span>
                        </td>            
                </tr>
                
            </table>
        </div>
    </form>
    <div style="clear:both;"></div>
</div>